package com.ewanghuiju.app.presenter.my;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.my.VipUpdataContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.BuyDailiInfoBean;
import com.ewanghuiju.app.model.http.response.BaseResponse;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/16
 */
public class VipUpdataPresenter extends RxPresenter<VipUpdataContract.View> implements VipUpdataContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public VipUpdataPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getPtibuyDailiInfo() {

        addSubscribe(mDataManager.getPtibuyDailiInfo()
                        .compose(RxUtil.rxSchedulerHelper())
                        .compose(RxUtil.handleMyResultCannull())
                        .subscribeWith(new CommonSubscriber<Optional<BuyDailiInfoBean>>(mView) {
                            @Override
                            public void onNext(Optional<BuyDailiInfoBean> optional) {
                                if (mView != null)
                                    mView.showPtibuyDailiInfo(optional.getIncludeNull());
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
//                        if (mView != null)
//                            mView.showContentError();
                            }
                        })
        );

    }

    /**
     * 购买区域代理
     *
     * @param area_id
     */
    @Override
    public void ptibuyDaili(String area_id) {
        addSubscribe(mDataManager.ptibuyDaili(area_id)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<BaseResponse>>(mView) {
                    @Override
                    public void onNext(Optional<BaseResponse> optional) {
                        if (mView != null)
                            mView.showbuyDailiSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

}
